package bloodfang.data;
import java.util.HashMap;

public class KeyValueStore extends HashMap<String,Double> {

	private static final long serialVersionUID = -482043328197157372L;
	
	public void add(String key,double value){
		if(!this.containsKey(key))
			this.put(key, 0.);
		double cur = this.get(key);
		this.put(key, cur + value);
	}
	
	public double sum(){
		double sum = 0.;
		for(double d : this.values()){
			sum += d;
		}
		return sum;
	}
	
	public double get(String key){
		if(!this.containsKey(key)){
			System.err.println("Error: Key " + key + " not exists");
			return 0;
		}
		return super.get(key);
	}
	
	public void print(){
		for(String key : this.keySet()){
			System.out.printf("%-28s%.4f%n", key, this.get(key));
		}
	}
}
